module app.controller.api.FriendController;

import std.json;
import hunt.framework;
import app.repository.FriendRepository;
import app.response.ResultMsg;
import app.utils.RespCodeEnun;
import app.model.Friend;

class FriendController : Controller
{
    mixin MakeController;

    @Action Response index()
    {
        FriendRepository friendRepository = new FriendRepository();
        ResultMsg resultMsg = new ResultMsg();

        Friend[] friends = friendRepository.findAll();
        JSONValue[] items;
        foreach (Friend friend; friends)
        {
            JSONValue item;
            item["id"] = friend.id;
            item["path"] = friend.path;
            item["siteName"] = friend.siteName;
            item["desc"] = friend.desc;
            items ~= item;
        }

        resultMsg.code = RespCodeEnun.SUCCESS;
        resultMsg.msg = "success";
        resultMsg.data["data"] = items;

        return new JsonResponse(resultMsg);
    }
}
